package com.authine.cloudpivot.ext.applicationservice;

import com.alibaba.cola.dto.SingleResponse;
import com.alibaba.fastjson.JSONObject;
import com.authine.cloudpivot.ext.constants.ModelConst;
import com.authine.cloudpivot.ext.dto.system.OutApiClientDto;
import com.authine.cloudpivot.ext.utils.BoServiceUtils;
import com.authine.common.util.ObjectMapperUtils;
import com.authine.mvp.app.launcher.dto.bo.response.BOList;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;

import javax.ws.rs.POST;
import javax.ws.rs.Path;

import static com.authine.hermes.app.launcher.service.ApplicationServiceFoundation.CUSTOM_SERVICE;

/**
 * @Author hxd
 * @Date 2021/9/27 16:21
 * @Description  对外api访问客户端模型
 **/

@Path("OutApiClientService")
@Slf4j
public class OutApiClientService {


    @Path("getByGomroUsername")
    @POST
    @Operation(summary = "out-api:根据固买系统用户名获取数据", tags = CUSTOM_SERVICE)
    public OutApiClientDto getByGomroUsername(OutApiClientDto dto){

        SingleResponse<BOList> list = BoServiceUtils.findListBySimple(ModelConst.T_OUT_API_CLIENT, "gomro_username", dto.getGomro_username());
        if (list.getData().getTotal() == 0) {
            return  null;
        }

        return ObjectMapperUtils.fromJSON(JSONObject.toJSONString(list.getData().getData().get(0)), OutApiClientDto.class);

    }
}
